// SPU管理模块接口
import request from '@/utils/request'
import { HasSpuResponseData, AllTrademark, AllSpuImg, SaleAttrResponseData, AllSaleAttrResponseData, SpuData, SkuData, SkuInfoData } from './type'
enum API {
    // 获取已有的SPU的数据
    HASSPU_URL = '/admin/product/',
    // 获取全部品牌名称的数据
    AllTRADEMARK_URL = '/admin/product/baseTrademark/getTrademarkList',
    // spu下全部售卖商品的图片
    IMAGE_URL = '/admin/product/spuImageList/',
    // spu已有的销售属性接口
    HASSALEATTR_URL = '/admin/product/spuSaleAttrList/',
    // 获取全部销售属性
    ALLSALEATTR_URL = '/admin/product/baseSaleAttrList',

    // 添加spu
    ADDSPU_URL = '/admin/product/saveSpuInfo',
    // 修改spu
    UPDATESPU_UEL = '/admin/product/updateSpuInfo',
    // 添加一个sku
    ADDSKU_URL = '/admin/product/saveSkuInfo',
    // 查看某一个已有的spu下全部售卖的商品
    SKUINFO_URL = 'admin/product/findBySpuId/',
    // 删除已有的spu
    REMOVESPU_URL = 'admin/product/deleteSpu/'
}

// 获取某一个三级分类下已有的SPU数据
export const hasSpuAPI = (page: number, limit: number, category3Id: number | string) => request.get<any, HasSpuResponseData>(API.HASSPU_URL + `${page}/${limit}?category3Id=${category3Id}`)

// 获取全部品牌名称
export const allTrademarkAPI = () => request.get<any, AllTrademark>(API.AllTRADEMARK_URL)

// spu下全部售卖商品的图片
export const spuImageAPI = (spuId: number) => request.get<any, AllSpuImg>(API.IMAGE_URL + spuId)

//  spu已有的销售属性
export const hasSaleAttrAPI = (spuId: number) => request.get<any, SaleAttrResponseData>(API.HASSALEATTR_URL + spuId)
 
// 获取全部销售属性
export const allSaleAttrAPI = () => request.get<any, AllSaleAttrResponseData >(API.ALLSALEATTR_URL)

// 添加或修改spu
export const AddOrUpdateSpu = (data: SpuData) => {
    if (data.id) {
        return request.post<any, any>(API.ADDSPU_URL)
    } else {
        return request.post<any, any>(API.UPDATESPU_UEL )
    }
}


// 添加一个sku
export const addSku = (data: SkuData) => request.post<any, any>(API.ADDSKU_URL, data)

// 查看某一个已有的spu下全部售卖的商品
export const skuList = (spuId: number) => request.get<any, SkuInfoData>(API.SKUINFO_URL + spuId)

// 删除已有的spu
export const removeSpu = (spuId: number) => request.delete<any, any>(API.REMOVESPU_URL + spuId)